package com.orange.score.android.service;

import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.WifiLock;
import android.os.IBinder;
import android.util.Log;

public class ScoreService extends Service
{
  private static final String TAG = ScoreService.class.getName();
  WifiManager.WifiLock wifiLock;
  boolean wifiOpen = false;

  public ScoreService()
  {
    this.wifiLock = null;
  }

  private void closeWifi()
  {
    if (this.wifiOpen)
    {
      WifiManager localWifiManager = (WifiManager)getSystemService("wifi");
      if (localWifiManager != null)
        localWifiManager.setWifiEnabled(false);
    }
  }

  private void openWifi()
  {
    WifiManager localWifiManager = (WifiManager)getSystemService("wifi");
    if (localWifiManager != null)
    {
      if (this.wifiLock == null)
      {
        Log.d(TAG, "create wifi lock");
        this.wifiLock = localWifiManager.createWifiLock("ScoreServiceWifiLock");
        this.wifiLock.setReferenceCounted(true);
      }
      if (this.wifiLock.isHeld())
        break label75;
      Log.d(TAG, "aquire wifi lock");
      this.wifiLock.acquire();
    }
    while (true)
    {
      return;
      label75: Log.d(TAG, "aquire wifi lock but it's already held");
    }
  }

  public IBinder onBind(Intent paramIntent)
  {
    return null;
  }

  public void onCreate()
  {
    super.onCreate();
    Log.d(TAG, toString() + " service <onCreate>");
  }

  public void onDestroy()
  {
    if ((this.wifiLock != null) && (this.wifiLock.isHeld()))
    {
      this.wifiLock.release();
      this.wifiLock = null;
    }
    super.onDestroy();
    Log.d(TAG, toString() + " service <Destroy>");
  }

  public void onStart(Intent paramIntent, int paramInt)
  {
    openWifi();
    super.onStart(paramIntent, paramInt);
    Log.d(TAG, toString() + " service <onStart>");
  }
}